home *** CD-ROM | disk | FTP | other *** search
- Path: redstone.interpath.net!mercury!softbase
- From: softbase@mercury.interpath.net (Scott McMahan - Softbase Systems)
- Newsgroups: comp.lang.c
- Subject: Re: Tradition or what?
- Date: 25 Feb 1996 19:36:57 GMT
- Organization: Interpath -- Providing Internet access to North Carolina
- Message-ID: <4gqdop$jfo@redstone.interpath.net>
- References: <4g0elg$mdr@redstone.interpath.net> <Dn4wML.5LJ@undergrad.math.uwaterloo.ca> <824950522snz@genesis.demon.co.uk>
- NNTP-Posting-Host: mercury.interpath.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Speaking of bizarre return values, do people realize 0 is used to mean
- both success, failure, and a valid return value in the standard
- library!? All three in the same library!
-
- 0 means success when an error code is returned. clock() is an
- example -- since -1 means error, any other value is successful.
- (I need to go back and check, but I think this is how it works.)
-
- 0 means failure when a valid value is returned like a pointer from
- malloc().
-
- Zero is also a valid value in strcmp which can't fail (unless you pass
- it bogus strings and it crashes) -- 0 means equal from the set of less
- than, equal, and greater than.
-
- No wonder C is confusing and error prone! Try defining a macro
- to represent what 0 means in the stdlib! :)
-
- I think this is the case against explicit tests against 0 in
- if, while, etc expressions which decide what to do based on the
- return value of a function. It's much more clear if there's no
- explicit test against 0.
-
- Scott
-
-